package com.lzy.cloud.base.service.impl;

import com.lzy.cloud.base.dto.BaseAreaDto;
import com.lzy.cloud.base.entity.BaseArea;
import com.lzy.cloud.base.mapper.BaseAreaMapperExt;
import com.lzy.cloud.base.service.AreaService;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AreaServiceImpl implements AreaService {

    @Autowired
    private BaseAreaMapperExt baseAreaMapperExt;

    @Override
    public Long insert(BaseAreaDto baseAreaDto) {
        BaseArea baseArea = DozerUtils.map(baseAreaDto, BaseArea.class);
            return baseAreaMapperExt.insertSelective(baseArea) > 0 ? baseArea.getId() : 0;
    }

    @Override
    public int update(BaseAreaDto baseAreaDto) {
        return baseAreaMapperExt.updateByPrimaryKeySelective(DozerUtils.map(baseAreaDto, BaseArea.class));
    }

    @Override
    public BaseAreaDto findById(Long aLong) {
        return DozerUtils.map(baseAreaMapperExt.selectByPrimaryKey(aLong), BaseAreaDto.class);
    }

    @Override
    public List<BaseAreaDto> getList() {
        return baseAreaMapperExt.getList();
    }

    @Override
    public List<BaseAreaDto> getListByParentId(Long parentId) {
        return baseAreaMapperExt.getListByParentId(parentId);
    }

    @Override
    public BaseAreaDto getAreaByCode(int code) {
        return baseAreaMapperExt.getAreaByCode(code);
    }

    @Override
    public BaseAreaDto findByAreaId(Long id) {
        return baseAreaMapperExt.findByAreaId(id);
    }
}
